#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
using webapp4U.DAL;
#endregion


namespace webapp4U.BOL
{
	 public class Products : BizObject
	 {
         #region Member Variables

         private Int32 _productID;

         private DateTime _addedDate;

         private String _addedBy;

         private Int32 _cateID;

         private Int32 _companyID;

         private Int32 _chatlieuID;

         private String _productCode;

         private String _nam;

         private String _trongluong;

         private String _title;

         private String _title_en;

         private String _description;

         private String _sKU;

         private Decimal _unitPrice;

         private String _imageUrl;

         private Int32 _displayOrder;

         #endregion



         #region Public Properties

         public Int32 ProductID
         {
             get { return _productID; }
             set { _productID = value; }
         }

         public DateTime AddedDate
         {
             get { return _addedDate; }
             set { _addedDate = value; }
         }

         public String AddedBy
         {
             get { return _addedBy; }
             set { _addedBy = value; }
         }

         public Int32 CateID
         {
             get { return _cateID; }
             set { _cateID = value; }
         }

         public Int32 CompanyID
         {
             get { return _companyID; }
             set { _companyID = value; }
         }

         public Int32 ChatlieuID
         {
             get { return _chatlieuID; }
             set { _chatlieuID = value; }
         }

         public String ProductCode
         {
             get { return _productCode; }
             set { _productCode = value; }
         }

         public String Nam
         {
             get { return _nam; }
             set { _nam = value; }
         }

         public String Trongluong
         {
             get { return _trongluong; }
             set { _trongluong = value; }
         }

         public String Title
         {
             get { return _title; }
             set { _title = value; }
         }

         public String Title_en
         {
             get { return _title_en; }
             set { _title_en = value; }
         }

         public String Description
         {
             get { return _description; }
             set { _description = value; }
         }

         public String SKU
         {
             get { return _sKU; }
             set { _sKU = value; }
         }

         public Decimal UnitPrice
         {
             get { return _unitPrice; }
             set { _unitPrice = value; }
         }

         public String ImageUrl
         {
             get { return _imageUrl; }
             set { _imageUrl = value; }
         }

         public Int32 DisplayOrder
         {
             get { return _displayOrder; }
             set { _displayOrder = value; }
         }

         #endregion


	     #region public static Methods

         public static List<Products> AdvanceSearch(string Keyword, int CateID, int CompanyID, int ChatlieuID, int Price, int PageIndex, int PageSize)
         {
             ProductsDAL db = new ProductsDAL();
             return db.AdvanceSearch(Keyword, CateID, CompanyID, ChatlieuID, Price, PageIndex, PageSize);
         }


         public static int GetCountAdvanceSearch(string Keyword, int CateID, int CompanyID, int ChatlieuID, int Price)
         {
             ProductsDAL db = new ProductsDAL();
             return db.GetCountAdvanceSearch(Keyword, CateID, CompanyID, ChatlieuID, Price);
         }

         public static List<Products> GetProductHomePage()
         {
             ProductsDAL db = new ProductsDAL();
             return db.GetProductHomePage();
         }


         public static string GetImageUrlByID(int ID)
         {
             try
             {
                 Products obj = Products.GetProductsByID(ID);
                 return obj.ImageUrl;
             }
             catch { return ""; }
         }

         public static List<Products> GetTopProduct(int CateID)
         {
             ProductsDAL db = new ProductsDAL();
             return db.GetTopProduct(CateID);
         }

         public static List<Products> GetProductsByCateID(Int32 CateID, int PageIndex, int PageSize)
         {
             ProductsDAL db = new ProductsDAL();
             return db.GetProductsByCateID(CateID, PageIndex, PageSize);
         }

          // Get ProductsCountByCateID
         public static int GetProductsCountByCateID(Int32 CateID)
         {
             ProductsDAL db = new ProductsDAL();
             return db.GetProductsCountByCateID(CateID);         
         }


         public static List<Products> Search(string Keyword, int CateID, int CompanyID)
         {
             ProductsDAL db = new ProductsDAL();
             return db.Search(Keyword,CateID,CompanyID);
         }

	     public static int Insert(Products obj)
	     {
		     ProductsDAL db = new ProductsDAL();
		     return db.Insert(obj);
	     }

	     public static bool Update(Products obj)
	     {
		     ProductsDAL db = new ProductsDAL();
		     return db.Update(obj);
	     }

	     public static bool Delete(Int32 ProductID)
         {
             try
             {
                 Products obj = GetProductsByID(ProductID);
                 // xoa hinh truoc roi moi xoa record
                 webapp4U.FileProcess.DeleteFile(Globals.PhysicalApplicationPath() + "/UserUpload/Products/" + obj.ImageUrl);
                 ProductsDAL db = new ProductsDAL();
                 return db.Delete(ProductID);
             }
             catch
             {
                 return false;
             }
	     }

	     public static Products GetProductsByID(Int32 ProductID)
	     {
		     ProductsDAL db = new ProductsDAL();
		     return db.GetProductsByID(ProductID);
	     }

	     //Get All Products
	     public static List<Products> GetAllProducts()
	     {
		     ProductsDAL db = new ProductsDAL();
		     return db.GetAllProducts(1, MAXROWS);
	     }

         //Get All Products
         public static List<Products> GetAllProducts(int PageIndex, int PageSize)
         {
             ProductsDAL db = new ProductsDAL();
             return db.GetAllProducts(PageIndex, PageSize);
         }

	     // Get Count All records of Table  Products
	     public static int GetCountProducts()
	     {
		     ProductsDAL db = new ProductsDAL();
		     return db.GetCountProducts();
	     }

	     // Get ProductsByCompanyID
	     public static List<Products> GetProductsByCompanyID(Int32 CompanyID,int PageIndex, int PageSize)
	     {
		     ProductsDAL db = new ProductsDAL();
		     return db.GetProductsByCompanyID(CompanyID, PageIndex, PageSize);
	     }

	     // Get ProductsCountByCompanyID
	     public static int GetProductsCountByCompanyID(Int32 CompanyID)
	     {
		     ProductsDAL db = new ProductsDAL();
		     return db.GetProductsCountByCompanyID(CompanyID);
	     }

	     #endregion
	 }
}
